module teapo.storage.attached.localStorage { export class StorageAccess implements attached.StorageAccess { private _nameCache: { [name: string]: { [name: string]: string; }; } = {}; private _localStorage: Storage,
private _editedKey: string) { byFullPath: PropertiesByFullPath,
callback: (error: Error) => void): void { for (var fullPath in byFullPath) if (byFullPath.hasOwnProperty(fullPath)) { var propBag = byFullPath[fullPath];
var cacheLine = this._nameCache[fullPath];
if (!cacheLine) continue;
for (var k in cacheLine) if (cacheLine.hasOwnProperty(k)) { this._localStorage.removeItem(key);
delete this._nameCache[fullPath];
var cacheLine = this._nameCache[fullPath] || (this._nameCache[fullPath] = {}); for (var k in propBag) if (propBag.hasOwnProperty(k)) { var key = cacheLine[k] || (cacheLine[k] = this._prefix + fullPath + '*' + k)
if (value === null || typeof value === 'undefined') { this._localStorage.removeItem(key);
this._localStorage.setItem(key, value);
this._updateEdited(timestamp);
callback: (error: Error, byFullPath: PropertiesByFullPath) => void): void { var allPaths = fullPaths ? false : true;
var byFullPath: PropertiesByFullPath = {}; for (var i = 0; i < fullPaths.length; i++) { byFullPath[fullPaths[i]] = {}; for (var i = 0; i < this._localStorage.length; i++) { var key = this._localStorage.key(i);
if (!startsWith(key, this._prefix)) continue;
var starPos = key.indexOf('*', this._prefix.length); if (starPos < 0) continue;
var fullPath = key.slice(this._prefix.length, starPos);
var propertyName = key.slice(starPos + 1);
var value = this._localStorage.getItem(key);
if (!fullPaths && !byFullPath[fullPath])
if (!byFullPath[fullPath])
byFullPath[fullPath] = {}; byFullPath[fullPath][propertyName] = value;
callback(null, byFullPath);
private _updateEdited(editedUTC: number) { this._localStorage.setItem(this._editedKey, <any>editedUTC);